{{>licenseInfo}}
package {{invokerPackage}};

{{#x-helidon-v3}}import java.util.concurrent.ExecutionException;
{{/x-helidon-v3}}

import io.helidon.common.GenericType;
{{#x-helidon-v3}}import io.helidon.common.reactive.Single;
import io.helidon.webclient.WebClientResponse;
{{/x-helidon-v3}}{{!
}}{{^x-helidon-v3}}import io.helidon.webclient.api.HttpClientResponse;
{{/x-helidon-v3}}

{{#appName}}
/**
 * Implementation of a generic-typed response.
 *
 * @param <T> type of the return value from the generated API method
 */
{{/appName}}
class ApiResponseBase<T> implements ApiResponse<T> {

  private final {{#x-helidon-v3}}Single<Web{{/x-helidon-v3}}{{^x-helidon-v3}}Http{{/x-helidon-v3}}ClientResponse{{#x-helidon-v3}}>{{/x-helidon-v3}} webClientResponse;
  private final GenericType<T> responseType;

  protected ApiResponseBase(GenericType<T> responseType, {{#x-helidon-v3}}Single<Web{{/x-helidon-v3}}{{^x-helidon-v3}}Http{{/x-helidon-v3}}ClientResponse{{#x-helidon-v3}}>{{/x-helidon-v3}} webClientResponse) {
    this.webClientResponse = webClientResponse;
    this.responseType = responseType;
  }

  @Override
  public {{#x-helidon-v3}}Single<WebClientResponse>{{/x-helidon-v3}}{{^x-helidon-v3}}HttpClientResponse{{/x-helidon-v3}} webClientResponse() {
    return webClientResponse;
  }

  @Override
  public {{#x-helidon-v3}}Single<{{/x-helidon-v3}}T{{#x-helidon-v3}}>{{/x-helidon-v3}} result() {{#x-helidon-v3}}throws ExecutionException, InterruptedException{{/x-helidon-v3}} {
    return webClientResponse.{{#x-helidon-v3}}get().content(){{/x-helidon-v3}}{{^x-helidon-v3}}entity(){{/x-helidon-v3}}.as(responseType);
  }
}